/*
    validate.methods.js
    功能：
        网站中常规验证的一个汇总

        分3部分：
            ①验证入口，一个验证项的所有验证都放在这里（只需要管这个）
            ②验证提示信息
            ③ajax验证

    demo:
        验证登录名
        validModule.loginname('vmooch02');

    $.Deferred()：延迟对象
        使用延迟对象来让外界获取异步回调中的数据
        好处：
            之前是把这种操作改成同步的，这样性能不好，
            现在仍然是异步操作，同时还能在外面获取回调
            中的数据
 */

var validModule= (function(validModule1){
    var validModule1 = {};

    //验证登录名的统一方法（之前写的在提示语上不太通用）
    validModule1.checkaccountname = function(options){
        //登录，注册，自定义提示
        var _this = this;
        
        var result = false;                                 //返回值
        
        var dfd = $.Deferred(); 
        
        var defaults = {                                    //默认值
            required     :_this.msg.loginname.required,
            regExp       :_this.msg.loginname.regExp,
            ajaxCallback :_this.msg.loginname.ajaxCallback,
            msgtype      : 'form',                           //提示的形式 form,dialog,
            validtype    : 'login'                          //验证类型,login:登录验证，reg:注册验证
        }
       
        var settings            = $.extend(true,defaults,options);

        var type                = settings.msgtype;
        var required            = settings.validtype =='login'?_this.msg.loginname.required:_this.msg.regloginname.required;
        var regExpmsg           = settings.validtype =='login'?_this.msg.loginname.regExp:_this.msg.regloginname.regExp; 
        var ajaxCallback        = settings.validtype =='login'?_this.msg.loginname.ajaxCallback:_this.msg.regloginname.ajaxCallback;
        var validtype           = settings.validtype;
        var val                 = settings.val;
        var regExp              = /^[a-z0-9]{5,11}$/.test(val);          //正则表达式

        //为空判断
        if(val == ''){
            if(type == 'form'){

                prj.formmsg("accountname","accountname_w",required);

            }else if(type == 'dialog'){

                $.dialog({
                    html:required + this.dialog.loginDialog,
                    type:'jpop'
                });

            }
            result = false;
            dfd.resolve(result);
            return dfd.promise();
        }else if(!regExp){
            //正则判断
            if(type == 'form'){

                prj.formmsg("accountname","accountname_w",regExpmsg);

            }else if(type == 'dialog'){

                $.dialog({
                    html:regExpmsg + this.dialog.loginDialog,
                    type:'jpop'
                });

            }

            result = false;
            dfd.resolve(result);
            return dfd.promise();
        }
        //ajax判断
        $.when(this.ajaxRequest.checkLoginname(val)).done(function(data){
            //登录和注册时对用户名的存在否的判断是相反的
            var validtype1 = validtype == 'login'? data ? false:true : data ? true:false;
            if(validtype1){
                if(type == 'form'){
                    prj.formmsg("accountname","accountname_w",ajaxCallback);
                }else if(type == 'dialog'){
                    $.dialog({
                        html:ajaxCallback,
                        type:'jalert'
                    });
                }
                result = 2;
            }else{
                if(type == 'form'){
                     prj.formmsg("accountname","accountname_w","",1);
                }
                result = true;
            }
            
            dfd.resolve(result);
        });

        return dfd.promise();
    };
    //密码(确认密码验证也包含在其中)
    validModule1.checkpassword = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.password.required,
            regExp       :_this.msg.password.regExp,
            // ajaxCallback :_this.msg.password.ajaxCallback,
            msgtype      : 'form',                               //提示的形式 form(表单),dialog(弹出框) 
            msgfield     :'passwordfield',      
            confirmpsw   :'',                                    //密码确认input的值
            validtype    :'common',                             //验证类型,common:常规验证，confirm:确认密码验证
            val          : ''                                 //密码的值           
        }
        var settings            = $.extend(true,defaults,options);
        
        var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var val                 = settings.val;
        var msgfield            = settings.msgfield;
        var confirmpsw          = settings.confirmpsw;
        var validtype           = settings.validtype;

        var regExp              = /^(?=.*[a-zA-Z0-9].*).{6,16}$/.test(val);

        //不是确认操作
        if(validtype != 'confirm'){
            if(val == ''){
                if(type == 'form'){
                    prj.formmsg(msgfield,msgfield+"_w",required);
                }else if(type == 'dialog'){
                    $.dialog({
                        html:required + this.dialog.loginDialog,
                        type:'jpop'
                    });
                }
                return false;
            }else if(!regExp){
                if(type == 'form'){
                    prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
                }else if(type == 'dialog'){
                    $.dialog({
                        html:regExpmsg + this.dialog.loginDialog,
                        type:'jpop'
                    });
                }
                return false;
            }else{
                if(type == 'form'){
                    prj.formmsg(msgfield,msgfield+"_w","",1);
                }
                return true;
            }
        }else{
            //是确认操作
            if(confirmpsw!=val){
                if(type == 'form'){
                    prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
                }else if(type == 'dialog'){
                    $.dialog({
                        html:regExpmsg + this.dialog.loginDialog,
                        type:'jpop'
                    });
                }
                return false;
            }else{
                if(type == 'form'){
                     prj.formmsg(msgfield,msgfield+"_w","",1);
                }
                return true;
            }
        }
    };
    // /*
    //         功能：密码验证2
    //         参数：
    //             val:密码的值
    //             psw_wrap_id:提示语容器
    //             oldpsw:旧密码
    // */
    // validModule1.regpassword = function(val){
    //     var regExp = /^(?=.*[a-zA-Z0-9].*).{6,16}$/.test(val);
    //     if(val == ''){
    //         prj.formmsg("passwordfield","passwordfield_w",this.msg.regpassword.required);
    //         // jAlert(this.msg.regpassword.required,'温馨提示');
    //         return false;
    //     }else{
    //         if(!regExp){
    //             prj.formmsg("passwordfield","passwordfield_w",this.msg.regpassword.regExp);
    //             // jAlert(this.msg.regpassword.regExp,'温馨提示');
    //             return false;
    //         }else{
    //             prj.formmsg("passwordfield","passwordfield_w","",1);
    //             return true;
    //         }
    //     }
    // };
    //验证新密码
    validModule1.validnewpsw = function(val,psw_wrap_id,oldpswval){
        var regExp = /^(?=.*[a-zA-Z0-9].*).{6,16}$/.test(val);
        if(val == ''){
            prj.formmsg(psw_wrap_id,psw_wrap_id+"_w","密码不能为空，请重新输入");
            // jAlert(this.msg.regpassword.required,'温馨提示');
            return false;
        }else{
            if(!regExp){
                prj.formmsg(psw_wrap_id,psw_wrap_id+"_w","新密码长度须是6~16位数字或字母或组合");
                // jAlert(this.msg.regpassword.regExp,'温馨提示');
                return false;
            }else if(oldpswval != "" && val == oldpswval){
                prj.formmsg(newpswId, newpswId+"_w", "新密码不能和原始密码一致");
                return false;
            }else{
                prj.formmsg(psw_wrap_id,psw_wrap_id+"_w","",1);
                return true;
            }
        }
    };
    //验证老密码
    // validModule1.validoldpsw = function(val,psw_wrap_id){
    //     var regExp = /^(?=.*[a-zA-Z0-9].*).{6,16}$/.test(val);
    //     if (val == '') {
    //         prj.formmsg(psw_wrap_id, psw_wrap_id+"_w", "旧密码不能为空，请重新输入");
    //         return false;
    //     }else{
    //         if(!regExp){
    //             prj.formmsg(psw_wrap_id, psw_wrap_id+"_w", "旧密码长度须在6~16位之间");
    //             return false;
    //         }else if(){
    //             $.ajax({
    //                 type:'POST',
    //                 url:"newmodifyPassword.htm",
    //                 data: params,
    //                 success:function(data){
    //                     if(data.res == 1){//验证成功
    //                         prj.formmsg(psw_wrap_id, psw_wrap_id+"_w", "", 1);
    //                     }else{//对应密码验证失败
    //                         prj.formmsg(psw_wrap_id, psw_wrap_id+"_w", "原密码输入有误，请重新输入");
    //                     }
    //                 },
    //                 Error:function(data){
    //                     // prj.loadingcancel();
    //                 }
    //             });
    //         }
            
    //     }
    // };
    //邮箱
    validModule1.email = function(options){
        var _this = this;
        var defaults = {
            regExp       :_this.msg.email.regExp,
            msgtype      : 'form',                               //提示的形式 form(表单),dialog(弹出框) 
            msgfield     : 'email',      
            val          : ''                                  //密码的值           
        }
        var settings            = $.extend(true,defaults,options);

        var val = settings.val;
        var msgfield = settings.msgfield;
        var regExpmsg = settings.regExp;

        var regExp = /^([_A-Za-z0-9\.]+)+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/.test(val);
        //邮箱不是必填的，可以通过
        if(val == ''){
            // jAlert(this.msg.email.required,'温馨提示');
            prj.formmsg(msgfield,msgfield+"_w","",0);
            return true;
        }else{
            if(!regExp){
                // jAlert(this.msg.email.regExp,'温馨提示');
                prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
                return false;
            }else{
                prj.formmsg(msgfield,msgfield+"_w","",1);
                return true;
            }
        }
    };
    //手机号(含ajax)
    validModule1.phone = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.phone.required,
            regExp       :_this.msg.phone.regExp,
            ajaxCallback :_this.msg.phone.ajaxCallback,
            msgtype      : 'form',                               //提示的形式 form(表单),dialog(弹出框) 
            msgfield     :'phone',      
            val          : ''                                  //密码的值           
        }
        var settings            = $.extend(true,defaults,options);
        
        // var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var ajaxCallback        = settings.ajaxCallback;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        var regExp = /^\d{11,12}$/.test(val);

        var dfd = $.Deferred();
        var result = '';
        if(val == ''){
            // jAlert(this.msg.phone.required,'温馨提示');
            prj.formmsg(msgfield,msgfield+"_w",required);
            result = false;

            dfd.resolve(result);
            return dfd.promise();
        }else if(!regExp){
            // jAlert(this.msg.phone.regExp,'温馨提示');
            prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
            result = false;

            dfd.resolve(result);
            return dfd.promise();
        }
        $.when(this.ajaxRequest.checkPhoneIsExist(val)).done(function(data){
            if(data.exist == 'true'){
                prj.formmsg(msgfield,msgfield+"_w",data.mes);
                result = false;
            }else{
                prj.formmsg(msgfield,msgfield+"_w","",1);
                result = true;
            }

            dfd.resolve(result);
        });

        return dfd.promise();
    };
    //手机号(含ajax)
    validModule1.registphone = function(options){
        var _this = this;
        var defaults = {
            required       :_this.msg.registphone.required,
            regExp         :_this.msg.registphone.regExp,
            ajaxCallback_1 :_this.msg.registphone.ajaxCallback_1,
            ajaxCallback_2 :_this.msg.registphone.ajaxCallback_2,
            msgtype        : 'form',                               //提示的形式 form(表单),dialog(弹出框) 
            msgfield       :'loginphone',      
            val            : '',                                   //密码的值      
            validtype      : 'reg'
        }
        var settings            = $.extend(true,defaults,options);
        
        var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var ajaxCallback_1      = settings.ajaxCallback_1;
        var ajaxCallback_2      = settings.ajaxCallback_2;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;
        var validtype           = settings.validtype; 

        var regExp = /^\d{11,12}$/.test(val);

        var dfd = $.Deferred();
        var result = '';
        if(val == ''){
            // jAlert(this.msg.phone.required,'温馨提示');
            if(type == 'form'){
                prj.formmsg(msgfield,msgfield+"_w",required);
            }else if(type == 'dialog'){
                $.dialog({
                    html:required
                });
            }
            result = {isExist:false};
            dfd.resolve(result);
            return dfd.promise();
        }else if(!regExp){
            // jAlert(this.msg.phone.regExp,'温馨提示');
            if(type == 'form'){
                prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
            }else if(type == 'dialog'){
                $.dialog({
                    html:regExpmsg
                });
            }

            result = {isExist:false};
            dfd.resolve(result);
            return dfd.promise();
        }
        $.when(this.ajaxRequest.checkAboutPhone(val)).done(function(data){
            var curMsg = '';
            if(data.isExist){
                //登录
                if(validtype == 'login'){
                    if(data.msg == 2){
                        curMsg = _this.msg.loginphone.ajaxCallback_2;
                        msgTip(curMsg);
                    }
                }else{
                    //注册
                    // curMsg = data.msg == 1?ajaxCallback_1:ajaxCallback_2;
                    if(data.msg==1){
                        curMsg = ajaxCallback_1;
                    }else{
                        curMsg = ajaxCallback_2;
                    }   
                    msgTip(curMsg);               
                }

                function msgTip(curMsg){
                    if(type == 'form'){
                        prj.formmsg(msgfield,msgfield+"_w",curMsg);
                    }else if(type == 'dialog'){
                        $.dialog({
                            html:curMsg
                        });
                    }
                }
                // prj.formmsg(msgfield,msgfield+"_w",ajaxCallback);
                result = {isExist:false,num:data.num};
            }else{
                if(validtype == 'login'){
                    //登录
                    if(data.msg == 0){
                        // curMsg = _this.msg.loginphone.ajaxCallback_1;
                        // if(type == 'form'){
                        //     prj.formmsg(msgfield,msgfield+"_w",curMsg);
                        // }else if(type == 'dialog'){
                        //     $.dialog({
                        //         html:curMsg
                        //     });
                        // }
                    }
                }else{
                    //注册
                    prj.formmsg(msgfield,msgfield+"_w","",1);
                }
                // result = true;
                result = {isExist:true,num:data.num};
            }

            dfd.resolve(result);
        });

        return dfd.promise();
    };

    //注册条款
    validModule1.agree = function(val){
        if(!val){
           prj.formmsg("roundedOne","roundedOne_w",this.msg.agree.required);
           return false;
        }else{
           prj.formmsg("roundedOne","roundedOne_w","",1);
           return true;
        }
    };
    //图形验证码(含ajax)
    validModule1.imgcode = function(options){
        var _this       = this;
        var defaults = {
            required     :_this.msg.imgcode.required,
            regExp       :_this.msg.imgcode.regExp,
            ajaxCallback :_this.msg.imgcode.ajaxCallback,
            msgtype      : 'form',                               //提示的形式 form(表单),dialog(弹出框) 
            msgfield     :'register_code',      
            val          : ''                                   //密码的值           
        }
        var settings            = $.extend(true,defaults,options);

        var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var ajaxCallback        = settings.ajaxCallback;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        var dfd         = $.Deferred();
        var result      = '';
        if( val == ""){
            if(type == 'form'){
                prj.formmsg(msgfield,msgfield+"_w",required);
            }else if(type == 'dialog'){
                $.dialog({
                    html:required,
                    type:'jalert'
                });
            }
            result = false;

            dfd.resolve(result);
            return dfd.promise();
        }else if( val.length < 4 ){
            if(type == 'form'){
               prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
            }else if(type == 'dialog'){
                $.dialog({
                    html:regExpmsg,
                    type:'jalert'
                });
            }
            result = false;

            dfd.resolve(result);
            return dfd.promise();
        }

        $.when(this.ajaxRequest.isCaptcha(val)).done(function(data){
            if(!data){
                if(type == 'form'){
                  prj.formmsg(msgfield,msgfield+"_w",ajaxCallback);
                }else if(type == 'dialog'){
                    $.dialog({
                        html:ajaxCallback,
                        type:'jalert'
                    });
                }
                result = false;
            }else{
                prj.formmsg(msgfield,msgfield+"_w","",1);
                result = true;
            }
            dfd.resolve(result);
        });
        return dfd.promise();
    };
    //推荐码
    validModule1.recommendCode = function(val){
        // var recomcode = $("#recommendCode");
        // var d = $.trim($("#recommendCode").val());
        // var regExp = /(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,8}$/.test(val);//6位数字和字母组合
        // if(val == ""){
        //     prj.formmsg("recommendCode","recommendCode_w","",0);
        //     return true;
        // }else{
        //     if (!regExp) {
        //          prj.formmsg("recommendCode","recommendCode_w",this.msg.recommendCode.regExp);
        //          return false; 
        //     }else{
                 prj.formmsg("recommendCode","recommendCode_w","",1);
                 return true; 
            //}
        //}
    }
    //真实姓名
    validModule1.realName = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.phone.required,
            regExp       :_this.msg.phone.regExp,
            val          : ''                                 //密码的值           
        }
        var settings            = $.extend(true,defaults,options);
        
        // var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var val                 = settings.val;

        var regExp = /^[.\u4E00-\u9FA5]{2,10}$/.test(val);
        if(val == ''){
            prj.formmsg("real_name","realName_w",this.msg.realName.required);
            return false;
        }else if(!regExp) {
            prj.formmsg("real_name","realName_w",this.msg.realName.regExp);
            return false;
        }else{
            prj.formmsg("real_name","realName_w","",1);
            return true;
        }
    };
    //银行账号
    validModule1.bankAccountNo = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.bankAccountNo.required,      //为空的提示语言
            regExp       :_this.msg.bankAccountNo.regExp,        //不符合验证规则的提示语言   
            msgtype      : 'form',                               //提示的形式 form,dialog 
            confirmval   :'',                                    //确认input的值
            msgfield     :'bankAccountNo',                       //form形式的提示，提示框的id前缀   
            val          :'',
            validtype    :'common'                              //验证类型,common:常规验证，confirm:确认密码验证
        }
        var settings            = $.extend(true,defaults,options);

        var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var val                 = settings.val;
        var msgfield            = settings.msgfield;
        var confirmval          = settings.confirmval;
        var validtype           = settings.validtype;

        //正则
        // var regExp = /[\u4E00-\u9FA5]/.test(val);
        var regExp = /^\d{10,20}$/.test(val);
        if(validtype != 'confirm'){
            if(val == ''){
                // jAlert(this.msg.bankAccountNo.required,'温馨提示');
                prj.formmsg(msgfield,msgfield+"_w",required);
                return false;
            }else if(!regExp){
                // jAlert(this.msg.bankAccountNo.regExp,'温馨提示');
                prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
                return false;
            }else{
                prj.formmsg(msgfield,msgfield+"_w","",1);
                return true;
            }
        }else{
            if(confirmval!=val ){
                prj.formmsg(msgfield,msgfield+"_w",_this.msg.confirmAccountNo.equalTo);
                return false;
            }else{
                prj.formmsg(msgfield,msgfield+"_w","",1);
                return true;
            }
        }
        
    };
        //银行账号
    validModule1.newBankAccountNo = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.newBankAccountNo.required,      //为空的提示语言
            regExp       :_this.msg.newBankAccountNo.regExp,        //不符合验证规则的提示语言   
            msgtype      : 'form',                               //提示的形式 form,dialog 
            confirmval   :'',                                    //确认input的值
            msgfield     :'newBankAccountNo',                       //form形式的提示，提示框的id前缀   
            val          :'',
            validtype    :'common',                              //验证类型,common:常规验证，confirm:确认密码验证
        }
        var settings            = $.extend(true,defaults,options);

        var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var val                 = settings.val;
        var msgfield            = settings.msgfield;
        var confirmval          = settings.confirmval;
        var validtype           = settings.validtype;
        var dfd         = $.Deferred();
        var result;
        var regExp = /^\d{10,20}$/.test(val);
        if(validtype != 'confirm'){
            if(val == ''){
                prj.formmsg(msgfield,msgfield+"_w",required);
                 result = false;
                 dfd.resolve(result);
                 return dfd.promise();
            }else if(!regExp){
                prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
                result = false;
                dfd.resolve(result);
                return dfd.promise();
            }else{
               $.when(this.ajaxRequest.checkNewBankNumber(val)).done(function(data){
                    if(!data){
                        if(type == 'form'){
                          prj.formmsg(msgfield,msgfield+"_w",ajaxCallback);
                        }else if(type == 'dialog'){
                            $.dialog({
                                html:ajaxCallback,
                                type:'jalert'
                            });
                        }
                        result = false;
                    }else{
                        prj.formmsg(msgfield,msgfield+"_w","",1);
                        result = true;
                    }
                    dfd.resolve(result);
                });
                return dfd.promise();
            }

        }else if(confirmval!=val ){
            prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
            result = false;
            dfd.resolve(result);
            return dfd.promise();
        } 
        
    };
    //确认银行账号
    validModule1.confirmAccountNo = function(val1,val2){
        if(!this.equal(val1, val2)){
            // jAlert(this.msg.confirmAccountNo.equalTo,'温馨提示');
            prj.formmsg("confirmAccountNo","confirmAccountNo_w",this.msg.confirmAccountNo.equalTo);
            return false;
        }else{
            prj.formmsg("confirmAccountNo","confirmAccountNo_w","",1);
            return true;
        } 
    };
    //银行名称
    validModule1.bankName = function(options){
        var _this = this;
        var defaults = {
            required     :_this.msg.bankName.required,      //为空的提示语言
            regExp       :_this.msg.bankName.regExp,        //不符合验证规则的提示语言   
            // msgtype      : 'form',                       //提示的形式 form,dialog 
            msgfield     :'bankName',                       //form形式的提示，提示框的id前缀   
            val          :''
        }
        var settings            = $.extend(true,defaults,options);

        // var type                = settings.msgtype;
        var required            = settings.required;
        var regExpmsg           = settings.regExp; 
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        var regExp = /^[\u2E80-\u9FFF \.,，．，。\w][^\s]+$/ig.test(val); 
        if(val == ''){
            // jAlert(this.msg.bankName.required,'温馨提示');
            prj.formmsg(msgfield,msgfield+"_w",required);
            return false;
        }else if(!regExp){
            prj.formmsg(msgfield,msgfield+"_w",regExpmsg);
            return false;
        }else{
            prj.formmsg(msgfield,msgfield+"_w","",1);
            return true;
        }
    };
    //账号类型
    validModule1.accountType = function(options){
        var that = this;
        var defaults = {
            required     :that.msg.accountType.required,       //为空的提示语言
            msgtype      : 'form',                      //提示的形式 form,dialog 
            msgfield     :'accountType',                       //form形式的提示，提示框的id前缀   
            val          :''
        }
        var settings            = $.extend(true,defaults,options);

        var required            = settings.required;
        var type                = settings.msgtype;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        if(val == -1){
            prj.formmsg(msgfield,msgfield+"_w",required);
            return false;
        }else{
            prj.formmsg(msgfield,msgfield+"_w","",1);
            return true;
        }
    };
    //省份
    validModule1.prov = function(options){
        var that = this;
        var defaults = {
            required     :that.msg.prov.required,      //为空的提示语言
            msgtype      : 'form',                      //提示的形式 form,dialog 
            msgfield     :'prov',                       //form形式的提示，提示框的id前缀   
            val          :''
        }
        var settings            = $.extend(true,defaults,options);

        var required            = settings.required;
        var type                = settings.msgtype;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        if(val == -1){
            prj.formmsg(msgfield,msgfield+"_w",required);
            return false;
        }else{
            prj.formmsg(msgfield,msgfield+"_w","",1);
            return true;
        }
    };
    //城市
    validModule1.accountcity = function(options){
        var that = this;
        var defaults = {
            required     : that.msg.accountcity.required,      //为空的提示语言
            msgtype      : 'form',                             //提示的形式 form,dialog 
            msgfield     : 'accountcity',                      //form形式的提示，提示框的id前缀   
            val          : ''
        }
        var settings            = $.extend(true,defaults,options);

        var required            = settings.required;
        var type                = settings.msgtype;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        if(val == -1){
            prj.formmsg(msgfield,msgfield+"_w",required);
            return false;
        }else{
            prj.formmsg(msgfield,msgfield+"_w","",1);
            return true;
        }
    };
    //支行
    validModule1.branchName = function(options){
        var that = this;
        var defaults = {
            required     : that.msg.branchName.required, //为空的提示语言
            regExp       : that.msg.branchName.regExp,   //正则提示
            msgtype      : 'form',                       //提示的形式 form,dialog 
            msgfield     : 'branchName',                 //form形式的提示，提示框的id前缀   
            val          : ''
        }
        var settings            = $.extend(true,defaults,options);

        var required            = settings.required;
        var type                = settings.msgtype;
        var val                 = settings.val;
        var msgfield            = settings.msgfield;

        // var regExp = /^.{2,20}[^\s]+$$/ig.test(val);
        var regExp = /^[\u2E80-\u9FFF \.,，．，。\w][^\s]+$/ig.test(val); 

        if(val == ''){
            prj.formmsg(msgfield,msgfield+"_w",required);
            return false;
        }else if(!regExp){
            prj.formmsg(msgfield,msgfield+"_w",this.msg.branchName.regExp);
            return false;
        }else{
            prj.formmsg(msgfield,msgfield+"_w","",1);
            return true;
        }
    };

    // 与业务不相关的验证
    validModule1.equal = function (val1, val2) {
        return (val1 == val2);
    };

    validModule1.minLength = function (val, length) {
        return val.length >= length;
    };

    validModule1.maxLength = function (val, length) {
        return val.length <= length;
    };

    /**范围验证**/
    validModule1.isRange = function (target, min, max) {
        return target >= min && target <= max;
    };

    //信息提醒
    validModule1.msg = {
        loginname:{
            required:"登录名不能为空,长度必须在5-11之间！",
            regExp:"登录名长度必须在5-11之间！",
            ajaxCallback:"该账号不存在，请重新填写"
        },
        regloginname:{
            required:"由5~11位小写字母或数字组合",
            regExp:"由5~11位小写字母或数字组合",
            ajaxCallback:"该账号已存在，您可重新填写或者在以下选择："
        },
        password:{
            required:"密码不能为空，请重新输入",
            regExp:"密码长度不够，请重新输入"
        },
        regpassword:{
            required:"密码不能为空，请重新输入",
            regExp:"由6-16位数字或字母或其组合"
        },
        agree:{
            required:"密码不能为空，请重新输入",
            regExp:"密码由6-16位的数字或字母或其组合"
        },
        phone:{
            required:"电话长度应为11~12位正确的手机号",
            regExp:"电话长度应为11~12位正确的手机号",
            ajaxCallback:"该号码已被注册，请重新输入"
        },
        registphone:{
            required:"电话长度应为11~12位正确的手机号",
            regExp:"电话长度应为11~12位正确的手机号",
            ajaxCallback_1:"该号码已被注册,您可以通过<a class='btn_blue btn_toLogin' href='javascript:;'>手机登录</a>方式快速登录账号",
            ajaxCallback_2:"您的电话号码已经被注册，您可以使用<a class='btn_blue btn_toReg' href='javascript:;'>账号注册</a>或者<a class='btn_blue' onclick='javascript:prj.openOnlineChat();' href='javascript:;'>联系在线客服</a>"
        },
        loginphone:{
            required:"电话长度应为11~12位正确的手机号",
            regExp:"电话长度应为11~12位正确的手机号",
            ajaxCallback_1:"该手机号码尚未注册，请您先去注册",
            ajaxCallback_2:"您的电话号码存在多个游戏账户，无法使用手机登录功能，请用账号密码登录"
        },
        confirm_password:{
            equalTo:"两次密码输入不一致"
        },
        email:{
            regExp:"请输入正确的邮箱地址"
        },
        realName:{
            required:"姓名不能为空",
            regExp:"姓名必须为中文，长度在2至10字符"
        },
        imgcode:{
            required:"您输入的验证码不正确",
            regExp:"您输入的验证码不正确",
            ajaxCallback:"您的验证码输入有误"
        },
        bankName:{
            required:"请选择存款银行"
        },
        accountType:{
            required:"请选择银行账号类型"
        },
        bankAccountNo:{
            required:"银行账号不能为空",
            regExp:"银行账号格式不正确,长度必须在 10和 20之间"
        },
        newBankAccountNo:{
            required:"银行账号不能为空",
            regExp:"银行账号格式不正确,长度必须在 10和 20之间",
            ajaxCallback:"该账号与当前绑定账号相同, 请更换!"
        },
        confirmAccountNo:{
            equalTo:"两次输入的银行账号不一致"
        },
        prov:{
            required:"请选择存款银行所在省份"
        },
        accountcity:{
            required:"请选择存款银行所在城市"
        },
        branchName:{
            required:"请输入银行卡开户网点",
            regExp:'请输入正确的开户网点'
        },
        //推荐码
        recommendCode:{
            required:"",
            regExp:"您输入的推荐码不正确"
        }
    };
    validModule1.dialog = {
        loginDialog : '<div id="jalert_panel"><a href="javascript:void(0)" id="jalert_ok" class="button dialog_ok">确认</a></div><a class="login_forpwd" target="_blank" href="getpassword.htm">忘记密码?</a>'
    }
    // =====================ajax请求验证=====================
    validModule1.ajaxRequest = {
        /*
                $.Deferred()：延迟对象
                使用延迟对象来让外界获取异步回调中的数据
                好处：
                    之前是把这种操作改成同步的，这样性能不好，
                    现在仍然是异步操作，同时还能在外面获取回调
                    中的数据
        */
        //ajax方法验证 验证码是否正确
        isCaptcha: function( target ) {
            var dfd = $.Deferred(); 
            var result = false;
            $.ajax({
                type    : 'POST',
                url     : 'registerCheckCaptcha.htm',
                data    : {captcha : target},
                success : function(data) {
                    if (data.checkCaptcha == 0){
                        result = false;
                    }else{
                        result = true;
                    }
                    dfd.resolve(result);
                },
                error : function(data) {
                    $.dialog({
                        html:'网络异常，请重试'
                    });
                    result = false;
                    dfd.resolve(result);
                }
            });
            return dfd.promise(); 
        },
        //检测新银行账号(检测唯一性)
        checkNewBankNumber: function( target ) {
            var dfd = $.Deferred(); 
            var params = {'action': 'checkBankNum','bankNum':$("#newBankAccountNo").val()};
            var result;
            $.ajax({
                type       : 'POST',
                url        : 'newmodifyCustomerBank.htm',
                data       : params,
                success : function(data) {
                    if(data.status == 0){
                        result = false;
                    }else{
                        result = true;
                    }
                    dfd.resolve(result);
                },
                error : function(data) {
                    $.dialog({
                        html:'网络异常，请重试'
                    });
                    result = false;
                    dfd.resolve(result);
                }
            });
            return dfd.promise(); 
        },
        //检查用户名是否存在
        checkLoginname: function( target ) {
            var dfd = $.Deferred(); 
            var loginname = 'v'+ target;
            var result = false;
            //ajax方法验证 验证码是否正确
            $.ajax({
                type       : 'POST',
                url        : 'checkLoginName.htm',
                data       : {loginname : loginname},
                success : function(data) {
                    if(data.exist == 'false'){
                        result = false;
                    }else{
                        result = true;
                    }
                    dfd.resolve(result);
                },
                error : function(data) {
                    $.dialog({
                        html:'网络异常，请重试'
                    });
                    result = false;
                    dfd.resolve(result);
                }
            });
            return dfd.promise(); 
        },
        //检查电话是否存在(ajax)
        checkPhoneIsExist:function( val ) {
            var dfd = $.Deferred(); 
            var result;           
            $.ajax({
                type    : 'post',
                url     : 'checkPhone.htm',
                data    : {phone:val,customerType:1},
                dataType:'json',
                success:function(results){
                    // var existPhone = results.exist;
                    dfd.resolve(results);
                },
                error:function(results){
                    $.dialog({
                        html:'网络异常，请重试'
                    });
                    result = true;
                    dfd.resolve(result);
                }
            });
            return dfd.promise();
        },
          //检查电话是否存在的各种情况
         checkAboutPhone:function(val){
            var dfd = $.Deferred(); 
            var result;
              $.ajax({
                  type:'post',
                  url:"registeruser.htm",
                  data:{phone:val,"action":"checkPhone"},
                  dataType:'json',
                  success:function(res){
                       if (res.status==1){
                           switch (res.num){
                               case 0:
                                    // prj.formmsg("loginphone","loginphone_w","",1);
                                    result = {isExist:false,msg:0,num:res.num};
                                    break;
                               case 1: //号码在系统中存在一个
                                    result = {isExist:true,msg:1,num:res.num};
                                    break;
                               default:
                                    // 号码在系统中存在2个或两个以上 
                                    result = {isExist:true,msg:2,num:res.num};
                            }                       
                        }else if(res.status==0){
                           $.dialog({
                              html:res.mes
                           });
                        }
                      dfd.resolve(result);
                  },
                  error:function(res){
                      $.dialog({
                          html:'网络异常，请重试'
                      });
                  }
              })
              return dfd.promise();
         }
    }   
    return validModule1;
})(validModule);
